<?php

class Pldkp_View_Helper_MultiSelector extends ZendX_JQuery_View_Helper_UiWidget
{
    public function multiSelector($id, $value = null, array $params = array(), array $attribs = array())
    {
        if (isset($attribs['options'])) {
            $options = $attribs['options'];
            unset($attribs['options']);
        }
        
        // Ensure that the proper javascript and css is loaded
        $baseUrl = $this->view->baseUrl();
        $this->jquery->addJavascriptFile($baseUrl . 'js/jquery/domec/jquery.domec-1.0.2.js');
        $this->jquery->addJavascriptFile($baseUrl . 'js/jquery/multiselector/jquery.multiselector.js');
        $this->jquery->addStylesheet($baseUrl . 'js/jquery/multiselector/jquery.multiselector.css');
        
        $attribs = $this->_prepareAttributes($id, $value, $attribs);
        $params = ZendX_JQuery::encodeJson($params);
        $js = sprintf('%s("#%s").multiselector(%s);',
            ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
            $attribs['id'],
            $params
        );
        $this->jquery->addOnLoad($js);
        
        return $this->view->formSelect($id, $value, $attribs, $options);
    }
}